package org.smile.homework01.kevin.FileMenu;

import java.util.ArrayList;

public class Menu extends MenuComponent{
    private ArrayList<MenuComponent> components = new ArrayList<MenuComponent>();
    //构造方法
    public Menu(String name,int level) {
        this.name = name;
        this.level = level;
    }
    //复写方法
    @Override
    public void add(MenuComponent menuComponent) {
        components.add(menuComponent);
    }
    @Override
    public void remove(MenuComponent menuComponent) {
        components.remove(menuComponent);
    }
    @Override
    public MenuComponent getChild(int index){
        return components.get(index);
    }
    @Override
    public void print(){
        for(int i = 0; i < level; i++){
            System.out.print("--");
        }
        System.out.println(name);
        for(MenuComponent menuComponent : components){
            menuComponent.print();
        }
    }
}
